home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 May / EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso / softwareupdate / system / amigados / advancedroutines / example1.c < prev    next >
C/C++ Source or Header  |  1996-10-10  |  6KB  |  203 lines

  1. /***********************************************************/
  2. /*                                                         */
  3. /* Amiga C Encyclopedia (ACE)           Amiga C Club (ACC) */
  4. /* --------------------------           ------------------ */
  5. /*                                                         */
  6. /* Manual:  AmigaDOS                    Amiga C Club       */
  7. /* Chapter: Advanced Routines           Tulevagen 22       */
  8. /* File:    Example1.c                  181 41  LIDINGO    */
  9. /* Author:  Anders Bjerin               SWEDEN             */
  10. /* Date:    93-03-17                                       */
  11. /* Version: 1.0                                            */
  12. /*                                                         */
  13. /*   Copyright 1993, Anders Bjerin - Amiga C Club (ACC)    */
  14. /*                                                         */
  15. /* Registered members may use this program freely in their */
  16. /*     own commercial/noncommercial programs/articles.     */
  17. /*                                                         */
  18. /***********************************************************/
  19.  
  20.  
  21. /* This example demonstrates how to use the Examine() function. */
  22. /* The program needs a file, directory or volume name as the    */
  23. /* only argument and it will print some interesting information */
  24. /* about given the object.                                      */
  25. /*                                                              */
  26. /* This example can be used with all versions of the dos        */
  27. /* library.                                                     */
  28.  
  29.  
  30.  
  31. /* Include the dos library definitions: */
  32. #include <dos/dos.h>
  33.  
  34. /* Include the memory type definitions: (MEMF_ANY, MEMF_CLEAR...) */
  35. #include <exec/memory.h>
  36.  
  37. /* Now we include the necessary function prototype files:         */
  38. #include <clib/dos_protos.h>       /* General dos functions...    */
  39. #include <clib/exec_protos.h>      /* System functions...         */
  40. #include <stdio.h>                 /* Std functions [printf()...] */
  41. #include <stdlib.h>                /* Std functions [exit()...]   */
  42. #include <string.h>                /* Std functions [strlen()...] */
  43.  
  44.  
  45.  
  46. /* Set name and version number: */
  47. UBYTE *version = "$VER: AmigaDOS/Advanced Routines/Example1 1.0";
  48.  
  49.  
  50.  
  51. /* Declared our own function(s): */
  52.  
  53. /* Our main function: */
  54. int main( int argc, char *argv[] );
  55.  
  56.  
  57.  
  58. /* Main function: */
  59.  
  60. int main( int argc, char *argv[] )
  61. {
  62.   /* "BCPL" pointer to our lock: */
  63.   BPTR my_lock;
  64.  
  65.   /* Pointer to our FileInfoBlock which we will allocate: */
  66.   struct FileInfoBlock *my_fib;
  67.  
  68.   /* AmigaDOS boolean check variable: */
  69.   LONG ok;
  70.  
  71.  
  72.  
  73.   /* This program needs one arguement:  */
  74.   /* (a file, directory or volume name) */
  75.   if( argc != 2 )
  76.   {
  77.     /* Wrong number of arguments! */
  78.     printf( "Error! Wrong number of arguments!\n" );
  79.     printf( "You must enter a file, directory or volume name.\n" );
  80.     printf( "Example1 Name/A\n" ); /* Simple template */
  81.  
  82.     /* Exit with an error code: */
  83.     exit( 20 );
  84.   }
  85.  
  86.  
  87.  
  88.   /* 1. Try to lock the object: (Shared access is enough.) */
  89.   my_lock = Lock( argv[ 1 ], SHARED_LOCK );
  90.   
  91.   /* Could we lock the object? */
  92.   if( !my_lock )
  93.   {
  94.     /* Problems! Inform the user: */
  95.     printf( "Could not lock the object!\n" );
  96.  
  97.     /* Exit with an error code: */
  98.     exit( 21 );
  99.   }
  100.  
  101.  
  102.  
  103.   /* 2. Allocate enough memory for a FileInfoBlock structure:  */
  104.   /* Since we want this example to be compatible with all dos  */
  105.   /* library versions we have to use the AllocMem() function.  */
  106.   /* If your program only should be used with dos library V37  */
  107.   /* or higher you should use the AllocDosObject() function.   */
  108.   /* (Any type of memory, preferably fast but if not available */
  109.   /* use chip, and clear it. The allocated memory will be long */
  110.   /* word aligned.)                                            */
  111.   my_fib = (struct FileInfoBlock *)
  112.      AllocMem( sizeof( struct FileInfoBlock ), MEMF_ANY | MEMF_CLEAR );
  113.  
  114.   /* Check if we have allocated the memory successfully: */
  115.   if( !my_fib )
  116.   {
  117.     /* Problems! Inform the user: */
  118.     printf( "Not enough memory!\n" );
  119.  
  120.     /* Unlock the object: */
  121.     UnLock( my_lock );
  122.  
  123.     /* Exit with an error code: */
  124.     exit( 22 );
  125.   };
  126.  
  127.  
  128.  
  129.   /* 3. Get some information about the object we have locked: */
  130.   ok = Examine( my_lock, my_fib );
  131.  
  132.   /* Any problems? */
  133.   if( !ok )
  134.   {
  135.     /* Problems! Inform the user: */
  136.     printf( "Could not examine the object!\n" );
  137.  
  138.     /* Deallocate the memory: */
  139.     FreeMem( my_fib, sizeof( struct FileInfoBlock ) );
  140.  
  141.     /* Unlock the object: */
  142.     UnLock( my_lock );
  143.  
  144.     /* Exit with an error code: */
  145.     exit( 23 );
  146.   }
  147.  
  148.  
  149.  
  150.   /* 4. You may now examine the FileInfoBlock structure! */
  151.   printf( "Name:      %s\n", my_fib->fib_FileName );
  152.  
  153.   if( my_fib->fib_DirEntryType < 0 )
  154.     printf( "Type:      File\n" );
  155.   else
  156.     printf( "Type:      Directory or Volume\n" );
  157.  
  158.   printf( "Size:      %d\n", my_fib->fib_Size );
  159.   printf( "Blocks:    %d\n", my_fib->fib_NumBlocks );
  160.   printf( "Comment:   %s\n",
  161.     my_fib->fib_Comment[0] ? my_fib->fib_Comment : "No comment" );
  162.  
  163.   printf( "Protection bits:\n" );
  164.   printf( "  Delete:  %s\n",
  165.     my_fib->fib_Protection & FIBF_DELETE ? "On" : "Off" );
  166.  
  167.   printf( "  Execute: %s\n",
  168.     my_fib->fib_Protection & FIBF_EXECUTE ? "On" : "Off" );
  169.  
  170.   printf( "  Write:   %s\n",
  171.     my_fib->fib_Protection & FIBF_WRITE ? "On" : "Off" );
  172.  
  173.   printf( "  Read:    %s\n",
  174.     my_fib->fib_Protection & FIBF_READ ? "On" : "Off" );
  175.  
  176.   printf( "  Archive: %s\n",
  177.     my_fib->fib_Protection & FIBF_ARCHIVE ? "On" : "Off" );
  178.  
  179.   printf( "  Pure:    %s\n",
  180.     my_fib->fib_Protection & FIBF_PURE ? "On" : "Off" );
  181.  
  182.   printf( "  Script:  %s\n",
  183.     my_fib->fib_Protection & FIBF_SCRIPT ? "On" : "Off" );
  184.  
  185.   printf( "Last changed: (Internal datestamp value)\n" );
  186.   printf( "  Days:    %d\n", my_fib->fib_Date.ds_Days );
  187.   printf( "  Minutes: %d\n", my_fib->fib_Date.ds_Minute );
  188.   printf( "  Ticks:   %d\n", my_fib->fib_Date.ds_Tick );
  189.  
  190.  
  191.  
  192.   /* 5. Deallocate the memory we have allocated: */
  193.   FreeMem( my_fib, sizeof( struct FileInfoBlock ) );
  194.  
  195.   /* 6. Unlock the file: */
  196.   UnLock( my_lock );  
  197.  
  198.   /* The End! */
  199.   exit( 0 );
  200. }
  201.  
  202.  
  203.